#include<bits/stdc++.h>
#define y1 Y1
#define fi first
#define endl "\n"
#define se second
#define PI acos(-1)
#define int long long
#define pb(x) push_back(x)
#define PII pair<int, int>
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define _for(i, a, b) for(int i = a; i <= b; ++i)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

const int N = 1e5 + 10;
char a[N];
int dp[1100][1100], n;

int cal(int l, int r) {
	if(l > r)return 0;
	if(l == r)return dp[l][r] = 1;
	if(dp[l][r])return dp[l][r];
	if(a[l] == a[r])return dp[l][r] = cal(l + 1, r - 1) + 2;
	else return dp[l][r] = max(cal(l + 1, r), cal(l, r - 1));
}

signed main() {
	IOS;
	cin >> n;
	_for(i, 1, n)cin >> a[i];
	 cal(1, n);
	 cout << dp[1][n] << endl;
	return 0;
}

